package com.action;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.apache.struts2.convention.annotation.Action;

import com.example.map.MachineMetrics;
import com.opensymphony.xwork2.ActionSupport;

public class MapAction extends ActionSupport {	
	
	public Map<String, List<MachineMetrics>> getEntry() {

	    // for datacenter 1
	    MachineMetrics metrics1 = new MachineMetrics();
	    metrics1.setAverage("10");
	    metrics1.setT2_95("100");
	    metrics1.setT2_99("200");
	    metrics1.setMachineName("machineA");
	    metrics1.setSyncs("100");
	    metrics1.setSyncsBehind("1000");

	    MachineMetrics metrics2 = new MachineMetrics();
	    metrics2.setAverage("20");
	    metrics2.setT2_95("200");
	    metrics2.setT2_99("300");
	    metrics2.setMachineName("machineB");
	    metrics2.setSyncs("200");
	    metrics2.setSyncsBehind("2000");

	    List<MachineMetrics> metricsA = new LinkedList<MachineMetrics>();
	    metricsA.add(metrics1);
	    metricsA.add(metrics2);

	    // for datacenter 2
	    MachineMetrics metrics3= new MachineMetrics();
	    metrics3.setAverage("30");
	    metrics3.setT2_95("300");
	    metrics3.setT2_99("300");
	    metrics3.setMachineName("machineC");
	    metrics3.setSyncs("300");
	    metrics3.setSyncsBehind("3000");

	    MachineMetrics metrics4 = new MachineMetrics();
	    metrics4.setAverage("40");
	    metrics4.setT2_95("400");
	    metrics4.setT2_99("400");
	    metrics4.setMachineName("machineD");
	    metrics4.setSyncs("400");
	    metrics4.setSyncsBehind("4000");

	    List<MachineMetrics> metricsB = new LinkedList<MachineMetrics>();
	    metricsB.add(metrics3);
	    metricsB.add(metrics4);     

	    Map<String, List<MachineMetrics>> holder = new LinkedHashMap<String, List<MachineMetrics>>();
	    holder.put("dc1", metricsA);
	    holder.put("dc2", metricsB);

	    return holder;   
	}
	
	public List<Map<String, String>> getList() {
		List<Map<String, String>> list = new ArrayList<Map<String, String>>();
		Map<String, String> map = new HashMap<String, String>();
		map.put("id", "1");
		map.put("name", "tom");
		map.put("age", "20");
		list.add(map);
		
		map = new HashMap<String, String>();
		map.put("id", "2");
		map.put("name", "jack");
		map.put("age", "25");
		list.add(map);
		
		map = new HashMap<String, String>();
		map.put("id", "3");
		map.put("name", "neo");
		map.put("age", "30");
		list.add(map);
		
		return list;
	}
	
	@Action("/map")
	public String execute() {
		return SUCCESS;
	}
	
}
